package model;

import model.type.ContactType;
import model.type.SubjectType;
import db.ImbiConnection;

public class Contact implements Comparable<Contact>{
	private final int id;
	private int subject;
	private int contactType;
	private String valueText;
	private int orderby;
	private int subjectType;
	private String note;
	
	public Contact(int id, int subject, int contactType, String valueText,
			int orderby, int subjectType, String note) {
		super();
		this.id = id;
		this.subject = subject;
		this.contactType = contactType;
		this.valueText = valueText;
		this.orderby = orderby;
		this.subjectType = subjectType;
		this.note = note;
	}

	public int getSubject() {
		return subject;
	}

	public void setSubject(int subject) {
		this.subject = subject;
	}

	public int getContactType() {
		return contactType;
	}

	public void setContactType(int contactType) {
		this.contactType = contactType;
	}

	public String getValueText() {
		return valueText;
	}

	public void setValueText(String valueText) {
		this.valueText = valueText;
	}

	public int getOrderby() {
		return orderby;
	}

	public void setOrderby(int orderby) {
		this.orderby = orderby;
	}

	public int getSubjectType() {
		return subjectType;
	}

	public void setSubjectType(int subjectType) {
		this.subjectType = subjectType;
	}

	public String getNote() {
		return note;
	}

	public void setNote(String note) {
		this.note = note;
	}

	public int getId() {
		return id;
	}
	
	/*OBJECT ACCESS METHODS*/
	
	public String getSubjectTypeString(){
		return SubjectType.getSubjectType(getSubjectType()).getType();
	}
	
	public String getContactTypeString(){
		return ContactType.getContactType(getContactType()).getType();
	}
	
	@Override
	public int compareTo(Contact o) {
		return ((Integer)getOrderby()).compareTo(o.getOrderby());		
	}
	
	public Object getSubjectObject(){
		if(getSubjectType() == SubjectType.ENTERPRISE)
			return ImbiConnection.getEnterpriseDAO().find(getSubject());
		if(getSubjectType() == SubjectType.PERSON)
			return ImbiConnection.getPersonDAO().find(getSubject());
		return null;
	}
}
